/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import entity.Conta;
import entity.ContaCor;
import entity.ContaInvest;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Tiago
 */
public class ContaDAO {
    
    private Connection connection;
   
    public ContaDAO() {
        this.connection = new ConnectionFactory().getConnection();
    }    
    public Conta getConta(int idCliente, int tipoConta) throws SQLException{
        Conta conta = null;
        String sql = "SELECT * FROM conta WHERE idCliente = ?";
        if (tipoConta == 1){
            conta = new ContaInvest();
        } else {
            conta = new ContaCor();
        }
        PreparedStatement stmt = connection.prepareStatement(sql);
        stmt.setInt(1, idCliente);
        ResultSet rs = stmt.executeQuery();
        while(rs != null && rs.next()) conta.setSaldo(rs.getDouble("saldo"));
        return conta;        
    }
}
